<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "advert".
 *
 * @property string $id
 * @property string $name
 * @property string $create_time
 */
class Advert extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'advert';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['create_time'], 'integer'],
            [['name'], 'string', 'max' => 128],
            [['name'], 'required', 'message' => '广告位名称不能为空'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '广告位',
            'create_time' => '创建时间',
        ];
    }
    public function save($runValidation = true, $attributeNames = null){
             if($this->isNewRecord){
                 $this->create_time=time();
             }
        return parent::save($runValidation, $attributeNames);
    }
    public static function getAdvert(){
        $advert=self::find()->asArray()->all();
        $data=[];
        foreach($advert as $v){
            $data[$v['id']]=$v['name'];
        }
        return $data;
    }
}
